package Runde1;

import java.util.*;

public class LVAManager {
	
	private static HashMap<Integer, LVA> LVAList;
	
	/**
	 * Creates an instance of the LVAManager which contains all courses.
	 */
	public LVAManager() {
		LVAList = new HashMap<Integer, LVA>();
	}
	
	
	/**
	 * Creates a course, catching the exceptions thrown by the constructor of LVA.
	 *
	 * @param lvaNr - unique lva number
	 * @param title - lva title
	 * @param earliestRegistration - earliest date to register  
	 * @param latestRegistration - latest date to register
	 * @param deregistration - latest datsman.e to deregister
	 * @param maxMembers - maximum amount of members. if unlimited value is integer.MAX_VALUE 
	 * @throws IllegalLVAException - LVA already exists or caught from LVA because of illegal arguments
	 */
	public void createLVA(int lvaNr, String title, Date earliestRegistration, Date latestRegistration,
			Date deregistration, int maxMembers) throws IllegalLVAException {
		
		try {
			if (LVAList.containsKey(lvaNr)) {
				throw new IllegalLVAException("LVA already exists");
			} 
			LVA newLVA = new LVA(lvaNr, title, earliestRegistration, latestRegistration, deregistration, maxMembers);
			LVAList.put(lvaNr, newLVA);
		} catch (IllegalLVAException e) {
			throw new IllegalLVAException(e.getMessage());
		}
	}
	
	/**
	 * Getter function for courses.
	 * 
	 * @param lvaNr - Unique course number.
	 * @return Course with specified number.
	 */
	public LVA getLVA(int lvaNr) {
		return LVAList.get(lvaNr);
	}
	
	
	/**
	 * Readable output of LVAList.
	 */
	public String toString() {
		String output = "";
		for (LVA lva : LVAList.values()) {
			output += lva;
		}
		return output;
	}
}